<template>
  <div class="caseComp">
    <div class="caseCompTitle">编辑查实情况</div>
    <el-form
      :model="initInfo"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="投诉事由：" prop="complaintReason">
            <el-input
              v-model="initInfo.complaintReason"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="涉及人数：" prop="involvedNum">
            <el-input
              v-model="initInfo.involvedNum"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="涉及金额：" prop="money">
            <el-input
              v-model="initInfo.money"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="案件简要：" prop="caseBrief">
            <el-input
              v-model="initInfo.caseBrief"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="caseCompBtn">
      <el-button type="primary" class="commonBut saveBtn" @click="save"
        >保存</el-button
      >
      <el-button type="default" class="commonBut" @click="finish"
        >取消</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: 'caseDepartment',
  props: {
    childData: {
      type: Object,
      required: true,
      default() {
        return {}
      },
    },
  },
  data() {
    var checkMoney = (rule, value, callback) => {
      if (!value) {
        callback()
      } else {
        var rePayTotal =
          /^(([0]|[1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/
        if (!rePayTotal.test(value)) {
          callback(new Error('金额格式不正确,必须大于或等于0,最多带有2位小数'))
        } else {
          if (value > 999999.99) {
            callback(new Error('金额需小于100万'))
          } else {
            callback()
          }
        }
      }
    }
    return {
      resolveStatus: [
        { value: 'YES', name: '是' },
        { value: 'NO', name: '否' },
      ],
      resolveType: [
        { value: '1', name: '用人单位已支付' },
        { value: '2', name: '已劳动仲裁' },
        { value: '3', name: '人民法院诉讼' },
        { value: '4', name: '其他' },
      ],
      initInfo: {
        id: '',
        complaintReason: '',
        involvedNum: '',
        money: '',
        caseBrief: '',
      },
      rules: {
        complaintReason: [
          { max: 20, message: '最多输入20个字', trigger: 'blur' },
        ],
        caseBrief: [{ max: 100, message: '最多输入100个字', trigger: 'blur' }],

        involvedNum: [
          {
            pattern: /^([1-9]\d*|[0]{1,1})$/,
            message: '仅可输入正整数或0',
            trigger: 'blur',
          },
        ],
        money: [{ validator: checkMoney, trigger: 'blur' }],
      },
    }
  },
  mounted() {
    this.initInfo = JSON.parse(JSON.stringify(this.childData))
  },
  methods: {
    save() {
      let params = this.initInfo
      delete params.createTime
      delete params.isDeleted
      delete params.effectiveStartDate
      delete params.effectiveEndDate
      delete params.creatorId
      delete params.updateTime
      delete params.updaterId
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios
            .post('api-r/complaint/registration/edit', params)
            .then((res) => {
              if (!res.data.hasError) {
                this.$message({
                  type: 'success',
                  message: '修改成功',
                })
                this.isLoading = false
                this.finish(1)
              } else {
                this.$message({
                  type: 'warning',
                  message: res.data.errorMsg || '修改失败',
                })
                this.isLoading = false
              }
            })
        } else {
        }
      })
    },
    finish(index) {
      this.$emit('callback', { success: index == 1 ? true : false })
    },
  },
}
</script>
<style lang="less" scoped>
.caseComp {
  border: 1px solid #dcdfe6;
  background-color: #f8f9fb;
  padding: 15px;
  &Title {
    color: #009588;
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 12px;
  }
  &List {
    line-height: 36px;
    height: 36px;
    font-size: 14px;
    color: #444;
    margin-bottom: 12px;
    &Title {
      display: inline-block;
      width: 85px;
      text-align: right;
    }
    &Input {
      width: calc(100% - 95px);
    }
    .input {
      width: calc(100% - 170px);
    }
  }
  &Btn {
    text-align: center;
    margin: 24px 0 10px;
    .el-button {
      width: 120px;
    }
  }
  /deep/ .el-radio__input.is-checked + .el-radio__label {
    color: #009588 !important;
  }
  /deep/.el-radio__input.is-checked .el-radio__inner {
    background: #009588 !important;
    border-color: #009588 !important;
  }
}
.caseCompTitleInput {
  width: calc(100% - 20px);
}
</style>
